<template>
  <el-dialog
    :title="!dataForm.payId ? '查看详情' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm"  ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="订单编号" style="margin-bottom: 8px;width: 400px">
        {{dataForm.orderSn}}
      </el-form-item>
      <el-form-item label="添加时间" style="margin-bottom: 0">
        {{dataForm.addTimeStr}}
      </el-form-item>
      <el-form-item label="收货地址"  style="margin-bottom: 0">
        国家：{{dataForm.country}} 州/省：{{dataForm.province}} 城市：{{dataForm.city}} 详细地址：{{dataForm.address}}
      </el-form-item>
      <el-form-item label="收件人"  style="margin-bottom: 10px">
        {{dataForm.name}} 电话：{{dataForm.mobile}} 邮编：{{dataForm.zipcode}}
      </el-form-item>
      <el-form-item label="快递公司"  style="margin-bottom: 10px">
        {{dataForm.shippingName}}
      </el-form-item>
      <el-form-item label="快递单号" prop="outTrackingNumber" style="margin-bottom: 8px;width: 400px">
        <el-input v-model="dataForm.outTrackingNumber" placeholder="包裹订单号"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        packages: [],
        visible: false,
        dataForm: {
          orderId: 0,
          outTrackingNumber: '',
        },
      }
    },
    methods: {
      init (id) {
        this.dataForm.orderId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.orderId) {
            this.$http({
              url: this.$http.adornUrl(`/order_pay/v9orderpay/info/${this.dataForm.orderId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.shippingName = data.order.shippingName
                this.dataForm.outTrackingNumber = data.order.outTrackingNumber
                this.dataForm.orderSn = data.order.orderSn
                this.dataForm.specialId = data.order.specialId
                this.dataForm.postscript = data.order.postscript
                this.dataForm.addservices = data.order.addservices
                this.dataForm.name = data.order.name
                this.dataForm.country = data.order.country
                this.dataForm.mobile = data.order.mobile
                this.dataForm.city = data.order.city
                this.dataForm.province = data.order.province
                this.dataForm.zipcode = data.order.zipcode
                this.dataForm.address = data.order.address
                this.dataForm.addTimeStr = data.order.addTimeStr
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/order/v9order/fahuo`),
              method: 'post',
              data: this.$http.adornData({
                'orderId': this.dataForm.orderId || undefined,
                'outTrackingNumber': this.dataForm.outTrackingNumber,
                'shippingStatus': 1
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
